home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / sun / lib2 / pgm_r.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-16  |  2.3 KB  |  71 lines

  1. /*    PGM_READ_WRITE . C
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3.  
  4. This software is copyright (C) by the Lawrence Berkeley Laboratory.
  5. Permission is granted to reproduce this software for non-commercial
  6. purposes provided that this notice is left intact.
  7.  
  8. It is acknowledged that the U.S. Government has rights to this software
  9. under Contract DE-AC03-765F00098 between the U.S.  Department of Energy
  10. and the University of California.
  11.  
  12. This software is provided as a professional and academic contribution
  13. for joint exchange. Thus, it is experimental, and is provided ``as is'',
  14. with no warranties of any kind whatsoever, no support, no promise of
  15. updates, or printed documentation. By using this software, you
  16. acknowledge that the Lawrence Berkeley Laboratory and Regents of the
  17. University of California shall have no liability with respect to the
  18. infringement of other copyrights by any part of this software.
  19.  
  20. For further information about this notice, contact William Johnston,
  21. Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  22. (wejohnston@lbl.gov)
  23.  
  24. For further information about this software, contact:
  25.     Jin Guojun
  26.     Bld. 50B, Rm. 2275, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  27.     g_jin@lbl.gov
  28.  
  29. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  30. %
  31. % AUTHOR:    Jin Guojun - LBL    8/1/91
  32. */
  33.  
  34. #include "header.def"
  35. #include "imagedef.h"
  36. #include "pgm.h"
  37.  
  38. read_pgm_image(img, maxval, format)
  39. U_IMAGE    *img;
  40. {
  41. register int    row, col;
  42. int    total = 0;
  43. gray    *gP, *grayrow = pgm_allocrow(img->width);
  44.  
  45. verify_buffer_size(&img->src, img->width * img->height, img->pxl_in, "pgsrc");
  46.  
  47. if (img->o_form != IFMT_SHORT){
  48. char    *obp=img->src;
  49.     for (row=0; row < img->height; row++){
  50.     total+=pgm_readpgmrow(img->IN_FP, grayrow, img->width, maxval, format);
  51.     if (sizeof(*grayrow) > 1)
  52.         for (col=img->width, gP=grayrow; col--; gP++)
  53.         *obp++ = *gP++;    /* convert to byte */
  54.     else    memcpy(obp, grayrow, img->width),
  55.         obp += img->width;
  56.     }
  57. }
  58. else    {
  59. short    *obp = (short *)img->src;
  60.     for (row=0; row < img->height; row++) {
  61.     total+=pgm_readpgmrow(img->IN_FP, grayrow, img->width, maxval, format);
  62.     if (img->in_form != img->o_form)
  63.         for (col=img->width, gP=grayrow; col--; gP++)
  64.         *obp++ = *gP++;    /* convert to short */
  65.     else    memcpy(obp, grayrow, img->width<<1),
  66.         obp += img->width;
  67.     }
  68. }
  69. return    total;
  70. }
  71.